package com.learn.algorithm;

public class SumOfFactorialN {

    /**
     * 计算前N个数的阶乘的累加和
     */
    public static long sumOfFactorial(int n) {
        long ans = 0;
        long current = 1;
        for (int i = 1; i <= n; i++) {
            current = current * i;
            ans += current;
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(sumOfFactorial(1));
        System.out.println(sumOfFactorial(2));
        System.out.println(sumOfFactorial(3));
        System.out.println(sumOfFactorial(4));
    }
}
